package cn.rongdao.jrkabao.ui.cashadvance.uicomponent;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRImageLoad;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.cashadvance.SelectBankCardBean;

/**
 * Created by jack on 2017/8/8
 */

public class SelectBankCardUIComponent extends RelativeLayout {
    public SelectBankCardUIComponent(Context context) {
        super(context);
    }

    public SelectBankCardUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SelectBankCardUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private ImageView ivAvatar;
    private TextView tvTitle;
    private View viewLine;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ivAvatar = (ImageView) findViewById(R.id.isbc_iv_avatar);
        tvTitle = (TextView) findViewById(R.id.isbc_tv_name);
        viewLine = findViewById(R.id.isbc_divisition);
    }

    public void setSelectBankCardContent(SelectBankCardBean data) {
        FRImageLoad.loadImage(data.getBank_icon(), ivAvatar, R.drawable.icon_no_distinguish_bank);
        if (data.isHighLight()) {
            SpannableStringBuilder textBuild = new SpannableStringBuilder();
            textBuild.append(data.getBank_name());
            textBuild.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.colorPrimary)), data.getHighlightedStart()
                    , data.getHighlightedEnd(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tvTitle.setText(textBuild);
        } else {
            tvTitle.setText(data.getBank_name());
        }
    }

    public void setViewLineVisible(int visible) {
        viewLine.setVisibility(visible);
    }
}
